/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.perficient.ibuzz.service;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.io.IOException;
import java.net.URI;

/**
 *
 * @author Tony.Deng
 */
public class PlatformBrowser implements Browser {

    @Override
    public void launch(String authorizationUrl) {
        try {
            boolean browsed = false;
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Action.BROWSE)) {
                    desktop.browse(URI.create(authorizationUrl));
                    browsed = true;
                }
            }
            if (!browsed) {
                String browser = "google-chrome";
                Runtime.getRuntime().exec(new String[]{browser, authorizationUrl});
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
